/*
*******************************************************************************
*                              (c) Copyright HighSun Techonology Company
*                                           All Rights Reserved
*
* File    : excitation_sample.h
* By      : HuangXi
* Version : V0.1
* Datetime: 2012-02-12 AM 09:53
* Description: Function declare for excitation sample operation
*******************************************************************************
*/
#ifndef __EXCITATION_SAMPLE_H__
#define __EXCITATION_SAMPLE_H__

#include <includes.h>

#define   TWELVE_POINTS         (12)    /* 12 points sample*/
#define   THIRTY_TWO_POINTS     (32)    /* 12 points sample*/
#define   SAMPLE_CHANNELS       (16)    /* Number of Sample Channel */
#define   SAMPLE_POINTS         (THIRTY_TWO_POINTS)    /* Points of sample */
#define   RING_BUFFER_SIZE      4       /* Length of sample buffer */
#define   PRINT_POINTS          0

typedef struct _adc_result
{
    Uint16 adc_result[SAMPLE_CHANNELS];
}ADC_RESULT;

typedef struct _sample_buff
{
    ADC_RESULT sample_buff[SAMPLE_POINTS];
}SAMPLE_BUFF;


typedef enum _adc_channel_name
{
    /* A */
    AD_REF_A = 0,

    /* Voltage of A,B phase */
    UFAB,

    /* Voltage of C,B phase */
    UFCB,

    /* Voltage of system */
    UXAB,

    /* Excitation voltage DC */
    ULO,

    AD_A5,

    AD_A6,

    AD_A7,

    
    /* B */
    AD_REF_B,
        
    /* Current of A phase */
    IFA,
        
    /* Current of C phase */
    IFC,
    
    AD_B3,
    
    /* Excitation current DC */
    ILO,

    AD_B5,

    AD_B6,

    AD_B7
}ADC_CHANNEL_NAME;



typedef struct _generator_parameter
{
    float64  Uab;
    float64  Uac;
    float64  Ucb;
    float64  Ia;
    float64  Ib;
    float64  Ic;
    float64  Ilo;
    float64  Ulo;
    float64  Uxab;
}GENERATOR_PARAMETER;


                                                 /* ERROR CODES                                        */
#define  ADC_NO_ERR            0                /* Function call was successful                       */
#define  ADC_RX_EMPTY          1                /* Rx buffer is empty, no character available         */



/* Function declare */
void     init_adc_buff(void);
void     adc_get_data(SAMPLE_BUFF *buf_ptr, INT8U *err);
BOOLEAN  adc_is_empty(void);
void     adc_put_sample_data(const INT8U which_point, const INT8U channel, const Uint16 adc_result);
void     compute_generator_parameter(GENERATOR_PARAMETER *generator_para);
void     debug_Uab(Uint16 *sample_buff_ptr);
void     debug_Ucb(Uint16 *sample_buff_ptr);
Uint32   get_vol_Uab(void);
Uint32   get_vol_Ucb(void);
void     print_points(void);
void     debug_Ia(Uint16 *sample_buff_ptr);
void     debug_Ic(Uint16 *sample_buff_ptr);
Uint32   get_cur_Ia(void);
Uint32   get_cur_Ic(void);
Uint32   get_P(void);
Uint32   get_Q(void);
Uint32   get_S(void);
Uint32   get_cos(void);
void     cal_P_Q_S(void);
void     debug_IL(Uint16 il_ad);
Uint32   get_il(void);
void     debug_UL(Uint16 ul_ad);
Uint32   get_ul(void);

#endif/*#ifndef __EXCITATION_SAMPLE_H__*/
